<?php
if (isset($InputData['show_url'])) {
    //进入复制鞋主秀链接的页面
    //连接作品数据模型
    require_once("{$CfgPara->root}/model/work.m.php");
    //获取作品信息
    $myWork = new work_m($CfgPara->database);
    $workMsg = $myWork->work_msg($InputData['show_url']);
    if (is_string($workMsg)) {
        echo($workMsg);
        goto page_end;
    }
    //检查当前用户是否为作品作者
    if (isset($_SESSION['user_id']) && $workMsg->Author == $_SESSION['user_id']) {
        $tittleText = '鞋主秀发布链接';
        require("{$viewRoot}tittle_back_bar{$viewEx}");
        $showUrl = $CfgPara->httproot . "/?controller=shoe_show_edit&work_id={$workMsg->Id}&user_login=1";
        require("{$viewRoot}shoe_show_copyurl{$viewEx}");
    } else {
        $warningText = '无权限访问';
        require("{$CfgPara->root}/view/warning_freetext_n_back.app.v.php");
    }
} elseif (isset($InputData['shoe_show_id']) ||
    (isset($InputData['work_id']) && isset ($InputData['work_index']))
) {
    //进入鞋主秀页面
    //连接鞋主秀数据模型
    require_once("{$CfgPara->root}/model/shoe_show.m.php");
    $myShoeShow = new shoe_show_m($CfgPara->database);
    //浏览计数
    if (isset ($InputData['shoe_show_id'])) {
        if (!isset($_COOKIE["shoe_show_view"][$InputData['shoe_show_id']])) {
            setcookie("shoe_show_view[{$InputData['shoe_show_id']}]", 1); //设置已浏览Cookie
            $result = $myShoeShow->show_view_count($InputData['shoe_show_id']);
        }
    } else {
        $i = "{$InputData['work_id']}_{$InputData['work_index']}";
        if (!isset($_COOKIE["shoe_show_view"][$i])) {
            setcookie("shoe_show_view[{$i}]", 1); //设置已浏览Cookie
            $result = $myShoeShow->show_view_count2($InputData['work_id'], $InputData['work_index']);
        }
    }

    // 获取信息
    if (isset ($InputData['shoe_show_id'])) {
        $shoeShowMsg = $myShoeShow->show_msg($InputData['shoe_show_id']);
    } else {
        $shoeShowMsg = $myShoeShow->show_msg2($InputData['work_id'], $InputData['work_index']);
    }
    if (is_string($shoeShowMsg)) {
        echo $shoeShowMsg;
        goto page_end;
    }
    //图片列表
    $shoeShowImgList = explode(";", $shoeShowMsg->Picture);
    //获取推荐人员列表 最新（第一页）的5人
    $result2 = $myShoeShow->show_recommend_list($shoeShowMsg->Id, 1, 5);
    if (is_string($result2)) {
        echo($result2);
        goto page_end;
    } elseif (is_array($result2)) {
        $shoeShowUpNames = '';
        foreach ($result2 as $value) {
            $shoeShowUpNames .= $value->UserName . ',';
        }
        $shoeShowUpNames = rtrim($shoeShowUpNames, ',');
    }
    $isRecommend = $myShoeShow->show_recommend_check($shoeShowMsg->Id);
    if ($isRecommend === true)//是否已推荐过
    {
        $recommendIconEx = '';
        $recommendColorClass = 'app-recomment-color';
    } else {
        $recommendIconEx = '-o';
        $recommendColorClass = 'am-link-muted';
    }
    $isCommend = $myShoeShow->show_comment_check($shoeShowMsg->Id);
    if ($isCommend === true)//是否已评论过
    {
        $commendIconEx = '';
    } else {
        $commendIconEx = '-o';
    }
    //仅pc版需要检测是否已被当前用户收藏
    if ($isTablet === TRUE) {
        require_once("{$CfgPara->root}/model/user.m.php");
        $myUser = new user_m();
        $isCollect = $myUser->user_collect_check($shoeShowMsg->Id, 1);
        if ($isCollect === TRUE) {
            $collectIconEx = '';
        } else {
            $collectIconEx = '-o';
        }
        //PC版需要作者完整信息
        if (!isset($userMsg)) {
            $userMsg = $myUser->user_msg('Id', $shoeShowMsg->Author);
        }
    }
    //连接评论控制器
    $InputData['comment_page'] = 1;//获取第一页的评论
    $InputData['comment_parent_type'] = 2;//鞋主秀的评论
    $InputData['comment_parent_id'] = $shoeShowMsg->Id;//鞋主秀的Id
    //如果是平板或PC需要展示所属作品的图片
    if ($isTablet === TRUE && isset($shoeShowMsg->WorkPicture)) {
        $workImg = make_img_name::make_img_mini_name(explode(';', $shoeShowMsg->WorkPicture)[0]);
    }
    //连接视图
    require("{$viewRoot}shoe_show{$viewEx}");
    //连接右侧栏菜单 仅手机需要
    if ($isTablet === FALSE)
        require("{$CfgPara->root}/view/menu_r_shoe_show.app.v.php");
} elseif (isset($InputData['shoe_show_up'])) {
    //鞋主秀推荐
    //连接数据模型
    if (!isset($_SESSION['user_id'])) exit('请登录');
    require_once("{$CfgPara->root}/model/shoe_show.m.php");
    $myShoeShow = new shoe_show_m($CfgPara->database);
    $result1 = $myShoeShow->show_recommend($InputData['shoe_show_up']);
    echo($result1);
    exit();
} elseif (isset($InputData['shoe_show_in_work'])) {
    //鞋主秀在作品页中迷你显示
    if (!isset($myShoeShow)) {
        require_once("{$CfgPara->root}/model/shoe_show.m.php");
        $myShoeShow = new shoe_show_m($CfgPara->database);
    }
    //获取作品中的鞋主秀信息 只获取一个
    $shoeShowList = $myShoeShow->show_list(shoe_show_m::ListForWork1, $InputData['shoe_show_in_work'], 1, 1);
    if (is_string($shoeShowList)) {
        echo($shoeShowList);
    } elseif (count($shoeShowList) > 0) {
        $shoeShowMsg = $shoeShowList[0];
        $shoeShowImgList = explode(";", $shoeShowMsg->Picture);
        require("{$viewRoot}show_view_mini{$viewEx}");
    }
}

page_end:;